FROM crpi-00rhylvrtlo3pvox.cn-beijing.personal.cr.aliyuncs.com/zhaoyansong/php:8.3.21-fpm-alpine3.20

# 更换Alpine镜像源为国内源，加速包下载
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories


# 步骤1: 安装基础工具和依赖库
RUN apk update && \
    apk add --no-cache \
        bash \
        git \
        curl \
        libpng \
        libjpeg-turbo \
        freetype \
        libzip \
        rabbitmq-c \
        hiredis \
        # 新增内核头文件，解决sockets扩展编译问题
        linux-headers && \
    rm -rf /var/cache/apk/*

# 步骤2: 安装构建依赖
RUN apk add --no-cache --virtual .build-deps \
        libpng-dev \
        libjpeg-turbo-dev \
        freetype-dev \
        libzip-dev \
        rabbitmq-c-dev \
        hiredis-dev \
        zlib-dev \
        autoconf \
        gcc \
        g++ \
        make && \
    rm -rf /var/cache/apk/*

# 步骤3: 配置并安装GD扩展
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/

# 步骤4: 安装PHP扩展
RUN docker-php-ext-install -j$(nproc) \
    gd \
    mysqli \
    pdo_mysql \
    zip \
    opcache \
    sockets \
    bcmath

# 步骤5: 安装PECL扩展
RUN pecl install redis amqp && \
    docker-php-ext-enable redis amqp

# 步骤6: 清理构建依赖
RUN apk del .build-deps

# 安装Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# 设置工作目录
WORKDIR /var/www/html

# 复制自定义PHP配置
COPY conf/php.ini /usr/local/etc/php/conf.d/custom.ini

# 调整权限
RUN chown -R www-data:www-data /var/www/html \
    && chmod -R 755 /var/www/html

# 暴露PHP-FPM端口
EXPOSE 9000

CMD ["php-fpm"]

